/**
 * <pre>项目名称:ssm-user-wdd
 * 文件名称:SendCode.java
 * 包名:com.jk.wdd.utils
 * 创建日期:2022年7月6日上午11:27:53
 * Copyright (c) 2022, yuxy123@gmail.com All Rights Reserved.</pre>
 */
package cn.itcast.hotel.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSONObject;


/**
 * 短信验证码工具类
 */
@SuppressWarnings("all")
public class SendCode {

    public static JSONObject sendCode(String phone){
        //请求路径
        String url = "https://api.netease.im/sms/sendcode.action";
        //head参数
        HashMap<String, Object> headParams = new HashMap<String, Object>();
        //App key
        headParams.put("AppKey", "07aea44f8e55c01da9e8b7d7796741c8");

        //6位随机数
        String round = Math.round(Math.random()*899999+100000)+"";
        headParams.put("Nonce", round);
        //时间戳
        String time = System.currentTimeMillis()+"";
        headParams.put("CurTime", time);
        //SHA1(AppSecret + Nonce + CurTime)，将该三个参数拼接的字符串进行 SHA1 哈希计算从而生成 16 进制字符（类型为 String，小写）
        headParams.put("CheckSum", CheckSumBuilder.getCheckSum("a72bd2e57b76", round, time));


        //body参数
        HashMap<String, Object> params = new HashMap<String, Object>();
        //手机号
        params.put("mobile", phone);
        //模板编号
        params.put("templateid", "19509869");
        //验证码
        params.put("authCode", round);

        System.out.println("验证码："+round);
        String str = HttpClientUtil.post2(url, params, headParams);
        System.out.println(str);


        //状态码，验证码

        JSONObject obj = JSONObject.parseObject(str);


        return obj;
    }


}
